<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <blockquote class="layui-elem-quote layui-text">
            鉴于小伙伴的普遍反馈，先温馨提醒两个常见“问题”：1. <a href="/doc/base/faq.html#form" target="_blank">为什么select/checkbox/radio没显示？</a> 2. <a href="/doc/modules/form.html#render" target="_blank">动态添加的表单元素如何更新？</a>
        </blockquote>

        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>表单集合演示</legend>
        </fieldset>
        <script src="https://csdnimg.cn/public/common/libs/jquery-1.9.1.min.js"></script>
        
        <!-- <script>$(function(){window.location.replace("http://www.baidu.com");})</script> -->
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">真实姓名:</label>
                <div class="layui-input-block">
                    <input style="width:300px;" value="<?php echo $row['name'] ?? '';?>" type="text" name="name" lay-verify="title" autocomplete="off" placeholder="请输入用户名" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">用户名:</label>
                <div class="layui-input-block">
                    <input style="width:300px;" value="<?php echo $row['username'] ?? '';?>" type="text" name="username" lay-verify="title" autocomplete="off" placeholder="请输入用户名" class="layui-input">
                </div>
            </div>
            <p>&nbsp;</p>
            <div class="layui-form-item">
                <label class="layui-form-label">密码:</label>
                <div class="layui-input-block">
                    <input style="width:300px;" value="<?php echo $row['pwd'] ?? '';?>" type="password" name="password" lay-verify="title" autocomplete="off" placeholder="请输入密码" class="layui-input">
                </div>
            </div>
            <p>&nbsp;</p>
            <div class="layui-form-item">
                <label class="layui-form-label">确认密码:</label>
                <div class="layui-input-block">
                    <input style="width:300px;" value="<?php echo $row['pwd'] ?? '';?>" type="password" name="repassword" lay-verify="title" autocomplete="off" placeholder="请确认密码" class="layui-input">
                </div>
            </div>
            <p>&nbsp;</p>
            <div class="layui-form-item">
                <label class="layui-form-label">手机号:</label>
                <div class="layui-input-block">
                    <input style="width:300px;" value="<?php echo $row['tel'] ?? '';?>" type="text" name="tel" lay-verify="title" autocomplete="off" placeholder="请输入手机号" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-block">
                    <input style="width:300px;" value="<?php echo $row['hidden'] ?? 'add';?>" type="hidden" name="hidden" lay-verify="title" autocomplete="off" placeholder="请输入手机号" class="layui-input">
                </div>
            </div>
            <!-- <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">普通文本域</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" class="layui-textarea"></textarea>
                </div>
            </div> -->
            <p>&nbsp;</p>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>


<script src="/static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="/js/jquery.min.js"></script>
<script>
    function dian(){
    ssk = $("#img").val();
    $("#imgs").css({"display":""});
    alert(ssk);
    // $(".xianshi").attr("src",);
    }   
</script>
<script>
    // $(document).ready(function(){
    //     $(".layui-this").click(function(){
    //         // $("option").text();
    //         alert(1);
    //     });
    // }); 
    //     var dan = $("input[placeholder='']").text();
    //     alert(dan);
        
    // function biao(){
    //     // class_id = $()
    //     alert('1');
    // }
</script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
//     layui.use('upload', function(){
//   var upload = layui.upload;
   
//   //执行实例
//   var uploadInst = upload.render({
//     elem: '#test1' //绑定元素
//     ,url: '/houtai/index/add_ok' //上传接口
//     ,done: function(res){
//       //上传完毕回调
//     }
//     ,error: function(){
//       //请求异常回调
//     }
//   });
// });
    layui.use(['form', 'layedit', 'laydate','upload'], function () {
        var form = layui.form
            , layer = layui.layer
            , upload = layui.upload
            , layedit = layui.layedit
            , laydate = layui.laydate;

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');
        
        //图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            // ,url: '/upload/'
            ,accept:'images'
            ,size:50000
            ,before: function(obj){

                obj.preview(function(index, file, result){

                    $('#demo1').attr('src', result);
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                //上传成功
                var demoText = $('#demoText');
                demoText.html('<span style="color: #4cae4c;">上传成功</span>');

                var fileupload = $(".image");
                fileupload.attr("value",res.data.src);
                console.log(fileupload.attr("value"));
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });

        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length == '') {
                    return '标题不能为空';
                }
            }
            , pass: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            // layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // })
            add_user_ok = data.field;
            // console.log(add_ok);
            $.post("/houtai/add_user_ok",{add_user_ok},function(add_user_bool){
                add_user_bool = JSON.parse(add_user_bool);
                if(add_user_bool['model']==4){
                    layer.msg(add_user_bool['think']+',两秒后自动跳转...',{
	            	icon: 6,
	            	time: 2000,
	            	end:function(){
						var index=parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                        parent.layer.close(index);
                        window.parent.location.reload();
                        // console.log(index);
                        
					}
	            });
				}else if(add_user_bool['model']==6){
                    layer.msg(add_user_bool['think']+',两秒后自动跳转...',{
	            	icon: 6,
	            	time: 2000,
	            	end:function(){
						var index=parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                        parent.layer.close(index);
                        window.parent.location.reload();
					}
	            });
				}else{
                    layer.msg(add_user_bool['think'], {icon: 5});
					}
                });
            return false;
        });

        //表单初始赋值
       


    });
</script>

</body>
</html>